# include <package.H>

Package::Package() : id(0), ttl(0), source(NULL), target(NULL), routed_to(NULL),
            h_favorable_direction(Num_Directions), v_favorable_direction(Num_Directions),
            num_deflections(0), num_routings(0), __is_in_queue(false), tiq(0), __is_deliveried(false)
{
  // Empty
}

Package::Package(const unsigned long & _id, Grid_Node * src, Grid_Node * tgt)
  : id(_id), ttl(0), source(src), target(tgt), routed_to(NULL),
    h_favorable_direction(Num_Directions), v_favorable_direction(Num_Directions),
    num_deflections(0), num_routings(0), __is_in_queue(false), tiq(0),  __is_deliveried(false)
{
  // Empty
}

Package::Package(const Package & p) : id(p.id), ttl(p.ttl), source(p.source), target(p.target), routed_to(p.routed_to),
                             h_favorable_direction(p.h_favorable_direction), v_favorable_direction(p.v_favorable_direction),
                             num_deflections(p.num_deflections), num_routings(p.num_routings),
                             __is_in_queue(p.__is_in_queue), tiq(p.tiq),  __is_deliveried(p.__is_deliveried)

{
  // Empty
}

Package::~Package()
{
  // Empty
}

const unsigned long & Package::get_id() const { return id; }

const unsigned short & Package::get_ttl() const { return ttl; }

const unsigned short & Package::get_tiq() const { return tiq; }

void Package::inc_ttl() { ++ttl; }

void Package::inc_tiq() { ++tiq; }

void Package::inc_num_deflections() { ++num_deflections; }

void Package::inc_num_routings() { ++num_routings; }

Grid_Node * Package::get_source_node() { return source; }

Grid_Node * Package::get_target_node() { return target; }

Grid_Node * Package::get_routed_to() { return routed_to; }

const unsigned long & Package::get_num_deflections() { return num_deflections; }

const unsigned long & Package::get_num_routings() { return num_routings; }

bool & Package::is_in_queue() { return __is_in_queue; }

bool & Package::is_deliveried() { return __is_deliveried; }

const unsigned short Package::get_num_favorable_directions() const
{
  int ret_val = 0;
  if (h_favorable_direction != Num_Directions)
    ++ret_val;
  if (v_favorable_direction != Num_Directions)
    ++ret_val;
  return ret_val;
}

const Direction Package::get_favorable_direction(Direction d) const{
    if ((d == h_favorable_direction) && h_favorable_direction != Num_Directions){
        return h_favorable_direction;
    }else{
        if (d == v_favorable_direction and v_favorable_direction != Num_Directions){
            return v_favorable_direction;
        }else{
            return Num_Directions;
        }
    }

}



void Package::reset()
{
  routed_to = NULL;
  v_favorable_direction = Num_Directions;
  h_favorable_direction = Num_Directions;
}

void Package::rout_to(Grid_Node * node)
{
  routed_to = node;
}

const Direction & Package::get_h_favorable_direction() const { return h_favorable_direction; }

Direction & Package::get_h_favorable_direction() { return h_favorable_direction; }

const Direction & Package::get_v_favorable_direction() const { return v_favorable_direction; }

Direction & Package::get_v_favorable_direction() { return v_favorable_direction; }

const std::string Package::to_string()
{
  return gnu::autosprintf("Paquete %ld", id);
}
